package routes

import (
    "SmartSearch/internal/controllers/feature/face"
    "SmartSearch/internal/controllers/feature/library"
    "SmartSearch/internal/controllers/file"
    "SmartSearch/internal/controllers/sys/department"
    "SmartSearch/internal/controllers/sys/device"
    "SmartSearch/internal/controllers/sys/role"
    "SmartSearch/internal/controllers/sys/user"
    "SmartSearch/internal/middleware"
    "github.com/gin-gonic/gin"
    "github.com/go-redis/redis/v8"
)

// RegisterAPIRoutes 注册API路由
func RegisterAPIRoutes(router *gin.Engine, redisClient *redis.Client) {
    // 初始化控制器
    userController := user.NewUserController()

    router.POST("/login", userController.Login)

    authMiddleware := middleware.NewAuthMiddleware()
    authGroup := router.Group("/", authMiddleware.AuthToken())
    {
        authGroup.GET("/logout")
        // 得到当前登录用户信息
        authGroup.GET("/currentUser")

        fileGroup := authGroup.Group("/file")
        {
            fileController := file.NewFileController()
            fileGroup.POST("/upload", fileController.Upload)
            fileGroup.POST("/uploadSlice", fileController.UploadSlice)
            fileGroup.GET("/mergeSlice", fileController.MergeSlice)
            fileGroup.GET("/download", fileController.Download)
        }

        sysGroup := authGroup.Group("/sys")
        {
            // 部门相关路由
            departmentGroup := sysGroup.Group("/department")
            {
                departmentController := department.NewDepartmentController()
                departmentGroup.POST("/add", departmentController.Add)
                departmentGroup.POST("/del", departmentController.Del)
                departmentGroup.GET("/list", departmentController.List)
                departmentGroup.POST("/update", departmentController.Update)
            }

            // 用户相关路由
            userGroup := sysGroup.Group("/user")
            {
                userGroup.POST("/add", userController.Add)
                userGroup.POST("/del", userController.Del)
                userGroup.GET("/list", userController.List)
                userGroup.POST("/update", userController.Update)
            }

            // 角色相关路由
            roleGroup := sysGroup.Group("/role")
            {
                roleController := role.NewRoleController()
                roleGroup.POST("/add", roleController.Add)
                roleGroup.POST("/del", roleController.Del)
                roleGroup.GET("/list", roleController.List)
                roleGroup.POST("/update", roleController.Update)
            }
            deviceGroup := sysGroup.Group("/device")
            {
                deviceController := device.NewDeviceController()
                deviceGroup.POST("/add", deviceController.Add)
                deviceGroup.POST("/del", deviceController.Del)
                deviceGroup.GET("/list", deviceController.List)
            }
        }
        featureGroup := authGroup.Group("/feature")
        {
            faceGroup := featureGroup.Group("/face")
            {
                faceController := face.NewFaceController()
                faceGroup.POST("/add", faceController.Add)
                faceGroup.POST("/del", faceController.Del)
                faceGroup.GET("/list", faceController.List)
                faceGroup.POST("/update", faceController.Update)
            }
            libraryGroup := featureGroup.Group("/library")
            {
                libraryController := library.NewLibraryController()
                libraryGroup.POST("/add", libraryController.Add)
                libraryGroup.POST("/del", libraryController.Del)
                libraryGroup.GET("/list", libraryController.List)
                libraryGroup.POST("/update", libraryController.Update)
            }
        }

    }
}
